<?php

namespace app\index\controller;

use app\admin\model\Article;
use app\common\controller\Frontend;
use app\common\model\Category;

class News extends Frontend
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    /**
     * 新闻咨询
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function index()
    {
        $cateInfo = Category::where(['nickname' => '/news', 'pid' => 0])
            ->field('id, pid, name, nickname, type, flag')
            ->find();
        $paginate = [];
        if ($cateInfo) {
            $paginate = Article::where(['category_id' => $cateInfo->id, 'status_data' => 1])
                ->order('weigh desc, id desc')
                ->field('id, name, createtime, updatetime')
                ->paginate(15, false, ['query' => $this->request->param()]);

        }
        $this->assign('cateInfo', $cateInfo);
        $this->assign('page', $paginate->render());
        $this->assign('paginate', $paginate);
        return $this->fetch();
    }
}